﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="GameExtensions.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011
//       Roland Rosenkranz (Glatzemann@email.de)
//
//    Parts of this code are based on code by Nick Gravelyn (http://blog.nickgravelyn.com/2009/07/a-more-robust-exception-system/)
// </copyright>
// <license>
//   This file is part of starLiGHT.Core.
//
//   starLiGHT.Core is free software: you can redistribute it and/or modify
//   it under the terms of the GNU Lesser General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   starLiGHT.Core is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public License
//   along with starLiGHT.Core. If not, see http://www.gnu.org/licenses/.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.Core are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 3197                  $:  Revision of last commit *
// * $Author:: unknown            $:  Author of last commit   *
// * $Date:: 2011-01-10 11:38:46 #$:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.Extensions
{
    #region Using Statements
    using System;
    using System.Diagnostics;
    using Microsoft.Xna.Framework;
    using starLiGHT.Game;

    #endregion

    public static class GameExtensions
    {
        public static void Run<T>() where T : Game, new()
        {
            if (Debugger.IsAttached)
            {
                using (var g = new T())
                {
                    g.Run();
                }
            }
            else
            {
                try
                {
                    using (var g = new T())
                    {
                        g.Run();
                    }
                }
                catch (Exception e)
                {
                    using (var g = new ExceptionGame(e))
                    {
                        g.Run();
                    }
                }
            }
        }
    }
}
